<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;

class CreateTable extends Command
{
    // 运行命令示例：php artisan createTable

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'createTable';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'create data table';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        try {
            // 读取 SQL 文件内容
            $sql = File::get(database_path('init.sql'));

            // 执行 SQL 语句
            return DB::unprepared($sql);
        } catch (\Exception $e) {
            v($e->getMessage());
        }
    }
}
